package cc3;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;


import sun.io.ByteToCharConverter;
import util.Config;


public class MyDoor {
	public static Logger log = Logger.getLogger(MyDoor.class);
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		enterDoor();
		
		//判断是否需要加血
		
		//heike12351@163.com   63646568
		
	}


	public static void enterDoor() {
//		processCC();
	}


	public static  void  processCC(String LOGIN_NAME,String COOKIE_VALUE,String PET,String MONEY) {
		String myPage = getMethod("http://cc.kongzhong.com/player/","",COOKIE_VALUE);
		//判断是否升级了  请求http://cc.kongzhong.com/ 如果返回“重新载入页面以获取源代码” 则说明需要升级了
		String r1 = getMethod("http://cc.kongzhong.com/","",COOKIE_VALUE);
		if(r1.indexOf("期待新的胜利")!=-1){
			//升级
			postMethod("http://cc.kongzhong.com/quest/","http://cc.kongzhong.com/quest/","action=nextstep",COOKIE_VALUE);
		}else{
			int myMoney = Integer.parseInt(formatParam(myPage,"银币:","\"><span").trim());
			if(myMoney>100*10000){
				String x = getMethod("http://cc.kongzhong.com/metro/", "", COOKIE_VALUE);
				if(x.indexOf("今天能见到PHILY的剩余次数是:")==-1){
					
				}else{
					int y = Integer.parseInt(formatParam(x, "今天能见到PHILY的剩余次数是:", "</p>"));
					if(y>0){
						log.info("LOGIN_NAME+获取一次免费的机会");
						getMethod("http://cc.kongzhong.com/thimble/start/", "", COOKIE_VALUE);
						
					}else{
						log.info(LOGIN_NAME+"今天三次免费的机会已经用完了");
					}
				}
				
				int flag = 0;
				while(myMoney>10*10000){
					postMethod("http://cc.kongzhong.com/thimble/play/9/0/", "", "ajax=1", COOKIE_VALUE);
					postMethod("http://cc.kongzhong.com/thimble/guess/0/", "", "ajax=1", COOKIE_VALUE);
					postMethod("http://cc.kongzhong.com/thimble/guess/1/", "", "ajax=1", COOKIE_VALUE);
					postMethod("http://cc.kongzhong.com/thimble/guess/2/", "", "ajax=1", COOKIE_VALUE);

					if(flag>50){
						log.info(LOGIN_NAME+"当前金币："+myMoney);
						myPage = getMethod("http://cc.kongzhong.com/player/","",COOKIE_VALUE);
						myMoney = Integer.parseInt(formatParam(myPage,"银币:","\"><span").trim());
						flag = 0;
					}
					flag ++;
				}
				
				log.info(LOGIN_NAME+"当前金币："+myMoney);
				getMethod("http://cc.kongzhong.com/thimble/leave/", "", COOKIE_VALUE);
				log.info(LOGIN_NAME+"运气罐游戏退出");
			}
			
			
			
			
			//根据不同等级 触发不同事件 目前低等级还是手工操作吧
			//8级时购买宠物和8级装备，并升级装备
			//属性大于60时开始存钱
			//存钱之后可以定时间触发换绿宝石来升级装备
			String level = formatParam(myPage.split("生命值")[0],">\\[","级\\]");
			String regEx="[^0-9]";   
			Pattern p = Pattern.compile(regEx);   
			Matcher m = p.matcher(level);  
			int l =  Integer.parseInt(m.replaceAll("").trim());
log.info(LOGIN_NAME+" 当前等级： "+l+" 级");
			if( l==100){
				//购买宠物
				System.out.println("购买");
//				http://cc.kongzhong.com/shop/section/weapons/
//				http://cc.kongzhong.com/shop/section/clothes/
				
//				http://cc.kongzhong.com/shop/section/hats/
				//获取商店当前最高等级武器
//				String weapons = getMethod("http://cc.kongzhong.com/shop/section/weapons/","",COOKIE_VALUE);
//				goodDetail(COOKIE_VALUE, myPage, weapons);
				String clothes = getMethod("http://cc.kongzhong.com/shop/section/clothes/","",COOKIE_VALUE);
				goodDetail(COOKIE_VALUE, myPage, clothes);
			}
			
			String pets = formatParam(myPage,"宠物列表","点此进入宠物商店");
			if(pets.indexOf("训练")==-1){
				if(l==8){
					//购买宠物
					
						//购买宠物
						String shopPetsPage =getMethod("http://cc.kongzhong.com/shop/section/zoo/","",COOKIE_VALUE);
						String topPet =formatParam(shopPetsPage,"科技产品","购买需要");
						
						String regex1 = "buy" + ".*?" + "shop";
						final Pattern pa1 = Pattern.compile(regex1, Pattern.CANON_EQ);
						final Matcher ma1 = pa1.matcher(topPet);
						String item="";
						String key  = "";
						while (ma1.find()) {
							String kk = ma1.group().replace("buy('", "").replace(", '/shop", "")
									.trim();
							System.out.println(kk);
							key = kk.split("',")[0].trim();
							item = kk.split("',")[1].trim();
							
							postMethod("http://cc.kongzhong.com/shop/json/","","key="+key+"&action=buy&item="+item+"&return_url=/shop/section/zoo/&type=&ajax_ext=2",COOKIE_VALUE);
							break;
						}
					}
			}else{
				//获取宠物id
				PET = formatParam(pets,"data-id=\"","\"");
			}
			
			if(l<=9){
				MONEY="1";
			}else{
				MONEY="500";
			}
			
			//贿赂保安
			goPolice(LOGIN_NAME,COOKIE_VALUE);
			
			//锻炼
			//低等级时，钱太多的话，循环都花掉3
			goTrain(myPage,MONEY,LOGIN_NAME,COOKIE_VALUE);
			
			//判断生命
			goLive(LOGIN_NAME,COOKIE_VALUE);
			
			//打地鼠
			String ratSearchPage = getMethod("http://cc.kongzhong.com/metro/track-rat/","",COOKIE_VALUE);
			if(ratSearchPage.indexOf("出错了")==-1){
			log.info(LOGIN_NAME+LOGIN_NAME+"打地鼠");
				getMethod("http://cc.kongzhong.com/metro/fight-rat/","",COOKIE_VALUE);
			}
			
			//判断生命
			goLive(LOGIN_NAME,COOKIE_VALUE);
			
			//攻击敌人
			attachAnamy(LOGIN_NAME,COOKIE_VALUE);
			
			//任务
			goJob(LOGIN_NAME,COOKIE_VALUE);
			
			//需要升级宠物技能
			goPet(PET,LOGIN_NAME,COOKIE_VALUE);
			
			//纳米彼里克
//			postMethod("http://cc.kongzhong.com/factory/start-petriks/","","player=1634204");
			
			//每天一次免费幸运大转盘
			postMethod("http://cc.kongzhong.com/casino/kubovich/","http://cc.kongzhong.com/casino/kubovich/","action=black",COOKIE_VALUE);
		}
	}


	private static void goodDetail(String COOKIE_VALUE, String myPage,
			String weapons) {
		String regex0 = "title=\"" + ".*?" + "\\|\\|";
		final Pattern pa0 = Pattern.compile(regex0, Pattern.CANON_EQ);
		final Matcher ma0 = pa0.matcher(weapons.split("产品功能")[1]);
		String topWeapon="";
		while (ma0.find()) {
			 topWeapon = ma0.group().replace("title=\"", "").replace("||", "")
					.trim();
			System.out.println(topWeapon);
			break;
		}
		String regex1 = "buy" + ".*?" + "shop";
		final Pattern pa1 = Pattern.compile(regex1, Pattern.CANON_EQ);
		final Matcher ma1 = pa1.matcher(weapons.split("产品功能")[1]);
		String item="";
		String key  = "";
		while (ma1.find()) {
			String kk = ma1.group().replace("buy('", "").replace(", '/shop", "")
					.trim();
			System.out.println(kk);
			key = kk.split("',")[0].trim();
			item = kk.split("',")[1].trim();
			break;
		}
		
		//获取我的口袋商品
		final List<String> goods = new ArrayList<String>();
		String regex = "title=\"" + ".*?" + "\\|\\|";
		final Pattern pa = Pattern.compile(regex, Pattern.CANON_EQ);
		final Matcher ma = pa.matcher(myPage);
		while (ma.find()) {
			String returnStr = ma.group().replace("title=\"", "").replace("||", "")
					.trim();
			if(returnStr!=null)
				goods.add(returnStr);
		}
		//购买装备
		
		boolean flag = true;
		for(String s:goods){
			if(s.equals(topWeapon)){
				flag=false;
				//如果没有带上，请带上装备
//						http://cc.kongzhong.com/player/json/dress/7390239/
				String ddd = formatParam(myPage,"title=\""+topWeapon,"装备");
				System.out.println("ddd:"+ddd);
				String dataId = formatParam(ddd,"data-id=\"","\"");
				System.out.println("dataId"+dataId);
				getMethod("http://cc.kongzhong.com/player/json/dress/"+dataId+"/","",COOKIE_VALUE);
				break;
			}
		}
		if(flag==true){
			//确定购买
			System.out.println("确定购买");
//					http://cc.kongzhong.com/shop/json/
//					key=969162a034af78c7e796eeb3724b545fe361c802&action=buy&item=21&return_url=/shop/section/weapons/&type=&ajax_ext=2
			postMethod("http://cc.kongzhong.com/shop/json/","","key="+key+"&"+"item="+item+"&&action=buy&return_url=/shop/section/weapons/&type=&ajax_ext=2",COOKIE_VALUE);
			
			String ddd = formatParam(myPage,"title=\""+topWeapon,"装备");
			System.out.println("ddd:"+ddd);
			String dataId = formatParam(ddd,"data-id=\"","\"");
			System.out.println("dataId"+dataId);
			getMethod("http://cc.kongzhong.com/player/json/dress/"+dataId+"/","",COOKIE_VALUE);
		}
	}


	private static void goPet(String PET,String LOGIN_NAME,String COOKIE_VALUE) {
		if(!PET.equals("false")){
			String petPage = getMethod("http://cc.kongzhong.com/petarena/train/"+PET+"/","",COOKIE_VALUE);
			int petHappy = Integer.parseInt(formatParam(petPage,"<span rel=\"tonus\">","</span>"));
			if(petHappy<30){
				//逗乐宠物
log.info(LOGIN_NAME+"逗乐宠物");
				postMethod("http://cc.kongzhong.com/petarena/mood/"+PET+"/","","action=mood&pet="+PET+"&ajax=1&postkey=ce81e095d12dde84f6730253c7f4b1fc",COOKIE_VALUE);
			}
			int focus = Integer.parseInt(formatParam(petPage,"机敏度</b><span class=\"num\">","</span>"));
			int loyality = Integer.parseInt(formatParam(petPage,"忠诚度</b><span class=\"num\">","</span>"));
			int mass = Integer.parseInt(formatParam(petPage,"吓唬技能</b><span class=\"num\">","</span>"));
			if(focus>loyality){
				//loyality
				postMethod("http://cc.kongzhong.com/petarena/train/"+PET+"/loyality/","","action=train&pet="+PET+"&skill=loyality&ajax=1&postkey=ce81e095d12dde84f6730253c7f4b1fc",COOKIE_VALUE);
log.info(LOGIN_NAME+"loyality update");
			}else{
				if(focus>mass){
					//mass
log.info(LOGIN_NAME+"mass");
					postMethod("http://cc.kongzhong.com/petarena/train/"+PET+"/mass/","","action=train&pet="+PET+"&skill=mass&ajax=1&postkey=ce81e095d12dde84f6730253c7f4b1fc",COOKIE_VALUE);
				}else{
					//focus
log.info(LOGIN_NAME+"focus");
					postMethod("http://cc.kongzhong.com/petarena/train/"+PET+"/focus/","","action=train&pet="+PET+"&skill=focus&ajax=1&postkey=ce81e095d12dde84f6730253c7f4b1fc",COOKIE_VALUE);
				}
			}
			
		}
	}


	private static void goTrain(String myPage,String MONEY,String LOGIN_NAME,String COOKIE_VALUE) {
		String moneyPage = myPage;
		int myMoney = Integer.parseInt(formatParam(moneyPage,"银币:","\"><span").trim());
		int preMoney = 0;
		while(myMoney>=Integer.parseInt(MONEY)*10000){
			if(preMoney==myMoney){
				break;
			}
			preMoney = myMoney;
			log.info(LOGIN_NAME+"myMoney:"+myMoney);
			goTrainer(COOKIE_VALUE);
			
			moneyPage = getMethod("http://cc.kongzhong.com/player/","",COOKIE_VALUE);
			myMoney = Integer.parseInt(formatParam(moneyPage,"银币:","\"><span").trim());
			log.info(LOGIN_NAME+"myMoney:"+myMoney);
		}
	}


	private static void goLive(String LOGIN_NAME,String COOKIE_VALUE) {
		String searchEnemy = getMethod("http://cc.kongzhong.com/alley/search/again/","",COOKIE_VALUE);//"werewolf=0&nowerewolf=1&type=equal"
		if(searchEnemy.indexOf("你的血量太低")!=-1){
log.info(LOGIN_NAME+"血量低在家吃了个饭");
			getMethod("http://cc.kongzhong.com/home/heal/","http://cc.kongzhong.com/home/",COOKIE_VALUE);
		}
	}


	private static void goPolice(String LOGIN_NAME,String COOKIE_VALUE) {
		String police = getMethod("http://cc.kongzhong.com/police/","",COOKIE_VALUE);
		int health = Integer.parseInt(formatParam(police,"目前的通缉度:","<i class=\"start\">"));
log.info(LOGIN_NAME+"被通缉健康值:"+health);
		if(health>-2){
log.info(LOGIN_NAME+"被通缉健康值:"+health+"贿赂保安");
			postMethod("http://cc.kongzhong.com/police/","","action=pay_fine",COOKIE_VALUE);
		}
		
	}


	private static void goJob(String LOGIN_NAME,String COOKIE_VALUE) {
		String job = "init";
		String t1 = getMethod("http://cc.kongzhong.com/nightclub/jobs/","",COOKIE_VALUE);
		String[] array = t1.split("完成该系列任务次");
		for(int i = 1;i<array.length;i++){
			if(!job.equals("init")){
				break;
			}
				String t2 = formatParam(array[i],"数:","</div>");
//				array2临时变量用于判断主线任务是否完成
				String[] array2 = t2.split("/");
				//判断主线任务是否已经完成
//				array3[0]是主线任务    array[1]是附加任务
				String[] array3 =array[i].split("附加任务");
				if(Integer.parseInt(array2[0].trim())<Integer.parseInt(array2[1].trim())){
					//主线任务
					//主线任务存在多个 根据percent判断当前需要执行哪个
					String[] array4 = array3[0].split("<span class=\"percent\">");
					job = formatParam(array4[0],"/job/","/");
				}else {
					//主线任务完成后判断是否需要做附加任务
					//附加任务存在多个 根据percent判断当前需要执行哪个
//					if(array3[1].indexOf("<span class=\"percent\">")!=-1){
//						String[] array4 = array3[1].split("<span class=\"percent\">");
//						job = formatParam(array4[0],"/job/","/");
//					}
				}
		}
log.info(LOGIN_NAME+"job:"+job);
		postMethod("http://cc.kongzhong.com/job/do/","","action=do&ajax=1&job="+job,COOKIE_VALUE);
	}


	private static void attachAnamy(String LOGIN_NAME,String COOKIE_VALUE) {
		//强对手
		//nowerewolf	1
//		type	strong
//		werewolf	0
		String searchEnemy = getMethod("http://cc.kongzhong.com/alley/search/again/","",COOKIE_VALUE);//"werewolf=0&nowerewolf=1&type=equal"
		if(searchEnemy.indexOf("你受伤了")!=-1){
			if(getMethod("http://cc.kongzhong.com/alley/","",COOKIE_VALUE).indexOf("巡逻倒计时")==-1){
				log.info(LOGIN_NAME+"开始巡逻");
				postMethod("http://cc.kongzhong.com/alley/","","action=patrol&region=14&time=10",COOKIE_VALUE);
			}else{
				log.info(LOGIN_NAME+"正在巡逻中");
			}
		}else{
			String 敌人IDS = formatParam(searchEnemy, "alleyAttack(", ");return");
			String[] 敌人IDarr = 敌人IDS.split(",");
			String 敌人ID = 敌人IDarr[0];
	log.info(LOGIN_NAME+"敌人ID" + 敌人ID);
			postMethod("http://cc.kongzhong.com/alley/","http://cc.kongzhong.com/alley/search/again/","action=attack&useitems=0&werewolf=0&player="+敌人ID,COOKIE_VALUE);
		}
	}


	private static void goTrainer(String COOKIE_VALUE) {
		//健身
		Integer caseNumber = 1;
		String trainer = getMethod("http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
		Integer t1 = Integer.parseInt(formatParam(trainer,"健康值</b><span class=\"num\">","</span>"));
		Integer small = t1;
		Integer t2 = Integer.parseInt(formatParam(trainer,"机智</b><span class=\"num\">","</span>"));
		Integer t3 = Integer.parseInt(formatParam(trainer,"力量</b><span class=\"num\">","</span>"));
		Integer t4 = Integer.parseInt(formatParam(trainer,"注意力</b><span class=\"num\">","</span>"));
		Integer t5 = Integer.parseInt(formatParam(trainer,"敏捷</b><span class=\"num\">","</span>"));
		Integer t6 = Integer.parseInt(formatParam(trainer,"魅力</b><span class=\"num\">","</span>"));
		Integer t7 = Integer.parseInt(formatParam(trainer,"耐力</b><span class=\"num\">","</span>"));
//			if(t1<small)caseNumber = 1;
		if(t2<small)caseNumber = 2;
		if(t3<small)caseNumber = 3;
		if(t4<small)caseNumber = 4;
		if(t5<small)caseNumber = 5;
		if(t6<small)caseNumber = 6;
		if(t7<small)caseNumber = 7;
		switch(caseNumber){
		case 1:
			postMethod("http://cc.kongzhong.com/trainer/train/health/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
			break;
		case 2:
			postMethod("http://cc.kongzhong.com/trainer/train/intuition/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
		    break;
		case 3:
			postMethod("http://cc.kongzhong.com/trainer/train/strength/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
			break;
		case 4:
			postMethod("http://cc.kongzhong.com/trainer/train/attention/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
			break;
		case 5:
			postMethod("http://cc.kongzhong.com/trainer/train/dexterity/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
			break;
		case 6:
			postMethod("http://cc.kongzhong.com/trainer/train/charism/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
			break;
		case 7:
			postMethod("http://cc.kongzhong.com/trainer/train/resistance/","http://cc.kongzhong.com/trainer/","",COOKIE_VALUE);
			break;
		}
	}
	
	
	public static void mainPage(String LOGIN_NAME,String COOKIE_VALUE){
		String s = "http://www.x1993.com/play/js16";
		String referer = "http://www.x1993.com/play/js28/";
		
		String total = getMethod(s, referer,COOKIE_VALUE);
		
		
		log.info(LOGIN_NAME+total);
	}


	private static String getMethod(String s, String referer,String COOKIE_VALUE) {
		String total = "";
		try {
			URL url = new URL(s);
			HttpURLConnection huc = (HttpURLConnection) url.openConnection();
			huc.setDoOutput(true);

			setHeader(huc, COOKIE_VALUE, referer, null);

			huc.connect();

			BufferedReader br = new BufferedReader(new InputStreamReader(
					huc.getInputStream(), "UTF-8"));
			String line = br.readLine();
			while (line != null) {
				line = br.readLine();
				total += line;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return total;
	}
	/**
	 * u post请求地址
	 * referer 请求后，跳转到哪里 
	 * value post 请求参数
	 **/
	@SuppressWarnings("deprecation")
	private static String postMethod(String u, String referer,String value,String COOKIE_VALUE) {
		String total = "";
		try {
			URL url = new URL(u);
			HttpURLConnection huc = (HttpURLConnection) url.openConnection();
			huc.setDoOutput(true);
			
			huc.setRequestProperty("X-Requested-With","XMLHttpRequest");
			huc.setRequestProperty("Cache-Control","no-cache");
			huc.setRequestProperty("Pragma","no-cache");
			huc.setRequestProperty("Content-Length","12");
			huc.setRequestProperty("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			huc.setRequestProperty("DNT","1");
			setHeader(huc, COOKIE_VALUE, referer, value);
			
			huc.connect();
			
			BufferedReader br = new BufferedReader(new InputStreamReader(
					huc.getInputStream(), "UTF-8"));
			String line = br.readLine();
			while (line != null) {
				line = br.readLine();
				total += line;
			}
//			StringBuilder sb = new StringBuilder();
//			InputStream is = huc.getInputStream();
//			byte[] b = new byte[102400];
//			int i = 0;
//			File file = new File("temp.txt");
//			PrintWriter output = new PrintWriter(new FileWriter(file));
//			String encoding = "gb2312";
//			ByteToCharConverter converter = ByteToCharConverter
//					.getConverter(encoding);
//			while ((i = is.read(b, 0, b.length)) != -1) {
//				// System.out.write(b, 0, i);
//				output.write(converter.convertAll(b), 0, i);
//			}

//			is.close();
//			output.close();
//
//			total = readTxt("temp.txt", "UTF-8");
//			System.out.println(total);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return total;
	}
	
	public static String readTxt(String filePathAndName, String encoding)
			throws IOException {
		encoding = encoding.trim();
		StringBuffer str = new StringBuffer("");
		String st = "";
		try {
			FileInputStream fs = new FileInputStream(filePathAndName);
			InputStreamReader isr;
			if (encoding.equals("")) {
				isr = new InputStreamReader(fs);
			} else {
				isr = new InputStreamReader(fs, encoding);
			}
			BufferedReader br = new BufferedReader(isr);
			try {
				String data = "";
				while ((data = br.readLine()) != null) {
					str.append(data + " ");
				}
			} catch (Exception e) {
				str.append(e.toString());
			}
			st = str.toString();
		} catch (IOException es) {
			st = "";
		}
		return st;
	}
	
	public static void setHeader(HttpURLConnection huc,String cookies,String referer,String postValue){
		try{
			huc.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
			if(postValue!=null&&!postValue.isEmpty())
				huc.setRequestProperty("Accept-Encoding","gzip, deflate");
			huc.setRequestProperty("Accept-Language","zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
			huc.setRequestProperty("Connection","keep-alive");
			huc.setRequestProperty("Cookie",cookies);
			huc.setRequestProperty("Host","cc.kongzhong.com");
			huc.setRequestProperty("Referer",referer);
			huc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
			if(postValue!=null&&!postValue.isEmpty()){
				StringBuffer sb = new StringBuffer();
				sb.append(postValue);
	
				OutputStream os = huc.getOutputStream();
				os.write(sb.toString().getBytes("UTF-8"));
				os.close();
	
				BufferedReader br = new BufferedReader(new InputStreamReader(
						huc.getInputStream(), "UTF-8"));
	
				huc.connect();
	
				String line = br.readLine();
				
				while (line != null) {
					line = br.readLine();

				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
			
	}
	
	/**
	 * 截取中间的值
	 * @param s
	 * @param startStr
	 * @param endStr
	 * @return
	 */
	private static String formatParam(String s, String startStr, String endStr) {
		String returnStr = "";
		String regex;
		final List<String> list = new ArrayList<String>();
		regex = startStr + ".*?" + endStr;
		final Pattern pa = Pattern.compile(regex, Pattern.CANON_EQ);
		final Matcher ma = pa.matcher(s);
		while (ma.find()) {
			returnStr = ma.group().replace(startStr, "").replace(endStr, "")
					.trim();
		}
		return returnStr;
	}

}
